Xfire Network Protocol

Original Author: Iain McGinniss (OpenFire)
Updated by: MacFire.org

Change History:
Rev Date Description
1 2007-08-16 Original revision by Iain McGinniss of OpenFire.
2 2008-06-15 Significant revision and lots of new information.

Document Overview

This document aims to provide a full specification for the Xfire instant messaging protocol, including packet structure and application program behavior. A lot of the information found in this document would not be available if it were not for the hard work of the XFireLib project team (http://xfirelib.sphene.net), who reverse engineered the protocol to write XFireLib. This document was written to formally document what they discovered, and to be provided as a basis for implementing Xfire communication libraries in alternative languages or on other platforms.

Note that this document may be incomplete. Not every aspect of the official Xfire client has been examined. Nor has every possible combination of scenarios. What follows should be adequate in most circumstances, but no guarnatees are made as to the correctness under all circumstances.

Section 2 describes the higher level protocol behaviors, while Section 3 describes the lower level packet interfaces.

Protocol Overview

This section describes the higher level protocol and application behaviors.

High Level Description

The client logs in to the server by establishing a TCP link (SOCK_STREAM) to the Xfire central server (cs.xfire.com) on port 25999. After sending a short keying sequence to the server, the client and server exchange sequences of bytes that are arranged into short packets (see Section 3).

After authenticating as a specific user, communication occurs between the client and the server, and may occur between clients. The official Xfire client appears to support client-to-client (peer to peer) communication for IM conversations using UDP datagrams. The official Xfire client also uses HTTP requests to retrieve some information, such as user avatar images and update downloads.

Data Encoding

Xfire uses UTF-8 string encoding. Integer values are transmitted in Little Endian byte order (least significant byte first). Refer to Section 3 for more information.

Log In Sequence

After successfully opening a TCP connection to cs.xfire.com, the following sequence of packets is exchanged.

Seq. # Source Content Comments
1 Client String "UA01" (not a packet) Keying sequence, in hex it is 0x55,0x41,0x30,0x31
2 Client Client Version packet Client version number
3 Server Login Challenge packet Server sends a value used to obscure the password (the "salt")
4 Client Authentication Data packet Client obscures the password using the "salt" and asks to be authenticated

After the above sequence of data exchanges, the Xfire server will respond with one of three known possible respones:

After authenticating successfully, the following sequence of packet exchanges occurs. Note that the order doesn't appear to be exact, and may change from version to version. For client implementation it is recommended to send the Client packets in the order they appear below.

Seq. # Source Content Comments
5 Server Authentication Success packet Success indicator, and information to be used during the session. Response 1 to auth packet.
6 Server Packet 400 Purpose is unknown.
7 Server Packet 141 Purpose is unknown.
8 Client Client Information packet Identifies current skin, theme, and language
9 Server Packet 151 Purpose is unknown. It appears to be a direct response the client info packet. Possibly some kind of skin/theme version info?
10 Server Packet 152 Purpose is unknown
11 Server Packet 148 Purpose is unknown - game information?
12 Server Packet 155 Purpose is unknown
13 Server Packet 157 Purpose is unknown
14 Server Packet 177 Purpose is unknown
15 Server Packet 163 Purpose is unknown
16 Server Friends List packet Contains list of all friends
17 Server Session ID Change packet Contains list of all friends that are online and their session IDs
18 Server Game status packet List of friend game status (game IDs, IPs, and ports)
19 Server In-Game Information packet In-game information for given friends. These appear to be received even for people not on our friend list (maybe friend of friend?).
20 Server Status Message Changed packet Initial status message for one online friend's session; multiple messages of this type may be received
21 Client Client Network Information packet Client sends network information, including how peers may contact us

Idle Time

During network idle time, the client should periodically send Keep-alive packets. They let the server know the client is still around. It is unknown the minimum amount of time before a server terminates a connection. Sending keep-alive packets every minute seems to be reasonable.

Information View

The official Xfire client has an information view that contains additional information related to what the user is doing. Usually this relates to something selected in the main window (friends list, server list, downloads, etc.), but there are also generic views when nothing is selected or prior to log in.

The information view is an HTML view created from many templates included with the Xfire client. The template files use a special syntax to identify keys for information. The Xfire client replaces those keys with information either readily available, or soon retrieved. The client appears to make specific requests for information from the Xfire server or from one of the HTTP servers operated by Xfire.

The extra information includes an avatar picture. The specific URL for a given user's avatar picture is likely indicated by the content of certain request packets, but as of this writing the decoding is unknown. The pictures are then retrieved via an HTTP request. Known locations are:

URL Description
http://media.xfire.com/xfire/xf/images/avatars/gallery/default/xfire.gif The default avatar. Other built-in avatars appear in this folder.
http://screenshot.xfire.com/avatar/... Specially uploaded avatars (?). Decoding the subfolder name is unknown. The specific picture image appears to be the username followed by an image format suffix.

Instant Messages

Messages are sent either:

There appear to be provisions in the network protocol to support either. The Client Network Information packet describes the availability to the master server. The Xfire client appears to support UPnP to put holes into visible router firewalls for a given port. Other clients can use that port to communicate with you. Indicating a 1 for a "NAT error" appears to work correctly to indicate that client-to-client communication is not possible.

Instant messages are plain UTF-8 text strings. As of this writing, the Xfire client support for chat rooms is not understood. Instant messages are usually directed to specific Session IDs, which are assigned to specific clients. It is assumed that chat rooms recieve their own Session ID which causes messages to be routed to all connected clients.

Friends of Friends

The Friends of Friends (Playing) feature allows an Xfire user to see what their friends' friends are playing. It can be seen as a community-building exercise because it allows friends to find new friends that play the same games they like.

In some ways, Friends of Friends is handled backwards. The Xfire server first sends a Game Status packet to the client. The game status packet assigns game IDs, addresses, and ports to given session IDs. The client would have previously received a Session ID packet listing known friends and their session IDs. Presumably, any unassigned session IDs in the Game Status packet represent friends of friends. So, the client must send a Friend of Friend Info request packet to get the associated username and nickname information.

Note that such friends are listed in the official Xfire client as Friends of Friends Playing. Presumably this means that when a player goes offline, the client should no longer display them in the list. These are indicated by Game Status packets with game IDs set to 0.

Packet Structure

All data exchanged over the Xfire network protocol except the initial "UA01" synchronization key are combined into well-formed packets. The packets contain a 4-byte header followed by a set of "attributes", or key/value pairs. The attribute map contains typed information that is used to uniquely decode a given message.

The general packet structure is as follows:

0 1 2 3 4 ...
0 Packet Length Packet Type ID Attribute map...

As indicated before, all multi-byte values are stored in Little Endian format (least-significant byte first).

Attribute Maps

Attribute maps contain up to 255 key/value pairs. The keys are formatted either as short, variable-length strings or as single-byte integer values. The key "domain" appears to depend upon the specific packet type. Most older packets use string keys, while many newer packets (higher number IDs) appear to use integer keys. Whereas string-based keys are somewhat easier to interpret, integer keys are more opaque in all observed data. It is believed that there are equivalent string-based keys for many (if not all) integer-based keys. That relationship is not well understood to to absence of applicable observed network traffic.

An attribute map starts with a 1-byte count of the number of attributes (key/value pairs) in the map. It is then followed by alternating keys and values. The value format is indicated in the next section.

0 1... ... ... ... ...
0 Attribute count Key 1 Value 1 ... Key N Value N

String-encoded keys appear as UTF-8 string data preceded by a 1-byte length field. Note that the string encoding is assumed to be UTF-8 given string attribute values use UTF-8 encoding; all observed keys may also be using ASCII encoding since they use no special characters. Because of the one-byte length field, a string-encoded attribute key may be at most 255 characters in length. No known keys have zero length. An example of a string-encoded key "userid" is:

0 1 2 3 4 5 6
0 0x06 0x75 0x73 0x65 0x72 0x69 0x64
Length u s e r i d

Integer-encoded keys appear as single-byte values in the data stream. They are followed immediately by values. The current guesses at the content for observed integer key IDs are shown below.

Key Value (Hex) Attribute Value Type Attribute Content
01Integer, or
Integer Array
User ID
02String, or
String Array
Name? In some cases it appears to be a username, in at least one other it was just a name or title string
04DID Array?
06String?
08String?
0bString?
0dString Array?
12Integer Array?
19Integer Array?
1aString Array?
1fInteger?
21Integer, or
Integer Array
? Flags? It apperas in packet 450, but has the value 0.
22Integer Array?
23Integer Array?
2eStringStatus Text Message? Only known appearance is packet 32
34Integer, or
Integer Array
?
4cAttribute Map, integer keys? Observed map keys 0x06, 0x08, 0x0b
4fInteger, or
Integer Array
Channel ID?
50Integer, or
Integer Array
Time stamp? (it appears as a timestamp in e.g. Channel1000.ini in the Xfire client)
51Integer Array? This appears to be a fileid. It appears in Channel1000.ini and in downloads metadata .ini files)
52Integer Array? Possibly either a AddTime or ModifyTime for a fileID. See Channel1000.ini.
53Integer Array? Possibly either a AddTime or ModifyTime for a fileID. See Channel1000.ini.
54String Array?
55Integer Array?
5cInteger Array?
5dInteger Array?
5eString Array?
6cInteger Array?
6dString Array?
72String Array?
81String Array?
91Integer Array?

The specific key domain for a packet is listed with each packet in Section 4.

Attribute Values

Attribute values are typed data streams. Each attribute value starts with a one-byte type ID field that uniquely indicates how to decode the remaining data for that attribute value. Known value types and their encoding is indicated below.

Type ID Description
0x01 A variable length string. The first two bytes of the data contain a 16-bit integer indicating the length of the string (number of bytes, not number of characters), followed by the string data. Strings use UTF-8 encoding.
0x02 A 32-bit integer. Signedness appears to depend upon the context, but usually appears to be unsigned.
0x03 A 128-bit value. This is likely a UUID (or GUID) given it is used for session identifiers.
0x04 An array of any other type. The first byte of an array indicates the type of each element in the array, using the Type IDs from this table. The next two bytes contains the number of entries in the array. The remaining bytes contain each value in consecutive order with no bytes in between.
0x05 An attribute map using string-encoded keys. The attribute map follows the same rules as defined for the main attribute map in the packet.
0x06 A 21-byte value. It always appears associated with something called a DID (possibly "download ID"), but it's exact purpose is unknown as of this writing.
0x07 In observed data this appeared to be a 64 bit (8 byte) integer.
0x08 TBD In some observed data this appeared to be a 1 byte integer. I will not commit to this definition until more data is analyzed.
0x09 An attribute map using integer-encoded keys. The attribute map follows the same rules as defined for the main attribute map in the packet.

An example of a simple packet is the Client Version packet, which has a single attribute named "version". It looks like this (with each byte's value displayed in hexadecimal, or the character equivalent where appropriate) :

0 1 2 3 4 5 6 7
0 12 00 03 00 01 07 76 65
Pkt Len Pkt ID Attr Cnt Key Len v e
8 72 73 69 6f 6e 02
55
00
r s i o n Val Type Value 85
16 00
00
Value 85

The total number of bytes in the packet is 18 (0x0012). The packet ID is 3 (0x0003), which makes this a Client Version packet. There is one attribute in the map. The attribute key is length 7 ("version"). The value type is 2 (integer), and the value is 85 (0x00000055).

Packet Descriptions

All known packets are listed below. Generally, packets sent from the client to the server use IDs between 0 and 127. Packets sent from the server to the client use IDs 128 and above.

Packet ID Description Key Encoding
1Authentication DataString
2Chat MessageString
3Client VersionString
5Request Info for Friend of FriendString
6Add Friend RequestString
7Accept Add Friend RequestString
8Decline Add Friend RequestString
9Remove FriendString
12Look up UserString
13Keep-AliveString
14Change NicknameString
16Client InformationString
17Client Network InformationString
18Client Skin (deprecated)String
23Unknown - Download information request?String
24Unknown - Download channel information request?String
32Status Text ChangeInteger
37UnknownInteger
128Login ChallengeString
129Login FailureString
130Login SuccessString
131Friends ListString
132Session ID ChangeString
133Server routed chat messageString
134New version availableString
135Game Status ChangeString
136Friends of Friends InfoString
137Outgoing Add Friend Request ConfirmationString
138Incoming Add-Friend RequestString
139Friend removedString
141UnknownInteger
143User Search ResultsString
144UnknownInteger
147Voice Chat InfoString
148UnknownInteger
151UnknownInteger
152UnknownInteger
154Friend statusString
155UnknownInteger
156In-Game Information ChangeString
157UnknownInteger
161Nickname ChangedInteger
163UnknownInteger
172UnknownInteger
173UnknownInteger
174UnknownInteger
176User Clan Information (for InfoView)Integer
177UnknownInteger
179UnknownInteger
400DID (?)String
401Unknown - Download info; response to packet 23String
402Unknown - DIDs for a specific download file ID?String
404Unknown - Information about a specific download file ID?String
406Unknown - Information about a specific downlaod file ID?String
450Channel information (?)Integer
452Unknown - Meta checksum for a specific download file ID?Integer

Authentication Data Packet

This packet contains the client's username and a hashed password (the authentication data for the user). It is sent from the client to the server in response to a Login Challenge packet. The server will respond with one of three known packets:

Packet ID 1
Attribute Key Domain String
Direction Client to Server

Attribute Map Contents:
KeyTypeDetails
name String The user name of the user that is attempting to log in.
password String The salted username and password of the user that is attempting to log in. The string is exactly 40 characters long and represents an SHA-1 hash computed per the following pseudocode:
String a = username + password + "UltimateArena";
int128 a_hash = ComputeSHA1(a);
String b = ToHexString(a_hash) + salt;
int128 b_hash = ComputeSHA1(b);
String result = ToHexString(b_hash);
The 'salt' value is that provided in the Login Challenge packet. The ToHexString function must return lower case characters for the SHA1 hash to be computed correctly. The "+" operators indicate string concatenation. The SHA-1 hash is computed on the string data, encoded to UTF-8.
flags Integer The purpose of this integer value is unknown. In all observed data it has been 0.

Chat Message Packet

SECTION NEEDS UPDATES

This message is sent by the client to the server, or directly to another user via UDP. The message can represent a number of things:

When chat messages are sent via the server, they will be received by the peer as a Server Routed Chat Message.

If communication is to be routed via the XFire server, client information messages should be sent regularly to prevent "high latency warnings" where the peer is a real XFire client. In OpenFire, these are sent with each real message, up to once every 5 seconds. It has not been determined what the threshold is for the XFire client to start reporting latency warnings.

Packet ID 2
Attribute Key Domain string
Direction Client to Server, Client to Client
Attribute Name Type Details
sid Session ID The session ID of the peer this message is intended for.
peermsg string keyed map Contains the real content of the message. See below for the structure of each payload.

The contents of the peermsg map vary depending on what this chat message represents. What is represented is indicated in the "msgtype" attribute in the map, a 32-bit integer value.

Client Version Packet

This contains a number identifying the Xfire client version. It should be the first packet sent from the client to the server immediately after the "UA01" synchronization key. The number appears to reflect the minor revision of the official Xfire client. So, for example, the official Xfire client version 1.85 sends number 85 in this packet. After successful authentication (see Authentication Data Packet), the Xfire server may respond with a Version Too Old packet if the number indicated in this packet is older than the current official Xfire client version.

Packet ID 3
Attribute Key Domain String
Direction Client to Server

Attribute Map Contents:
KeyTypeDetails
version Integer The version number of the client.

Request Info for Friend of Friend

This packet is used to request information for Friends of Friends. The client uses the session IDs sent to it by the initial Game Status packet. That packet may contain session IDs for people that are not Friends. This packet is used to request information about them. The response is a Friend of Friend Info packet.

Packet ID 5
Attribute Key Domain String
Direction Client to Server

Attribute Map Contents:
KeyTypeDetails
sid UUID Array Array of the session IDs for which the client is requesting information.

Add Friend Request Packet

This packet requests that a friend be added. The other user must accept the friendship request for the user to be added to your friends list. The request includes a personalized message. The server will respond with a confirmation, that may indicate an error occurred.

Packet ID 6
Attribute Key Domain String
Direction Client to Server

Attribute Map Contents:
KeyTypeDetails
Attribute Name Type Details
name String The username of the user to invite.
msg String The personalized message to be displayed to the recipient.

Accept Add Friend Request

The client sends this packet in response to an Incoming Add Friend Request when the user wishes to accept the invitation. It simply contains the username of the requestor.

Packet ID 7
Attribute Key Domain String
Direction Client to Server

Attribute Map Contents:
KeyTypeDetails
name string The username of the invitation to accept.

Decline Add Friend Request

The client sends this packet in response to an Incoming Add Friend Request when the user wishes to decline the invitation. It simply contains the username of the requestor.

Packet ID 8
Attribute Key Domain String
Direction Client to Server

Attribute Map Contents:
KeyTypeDetails
name string The username of the invitation to decline.

Remove Friend Packet

This packet requests that a friendship be terminated. The other user recieves a Friend Removed packet.

Packet ID 9
Attribute Key Domain String
Direction Client to Server

Attribute Map Contents:
KeyTypeDetails
userid Integer The user ID of the friend to remove.

Look up User Packet

This is sent by a client to search for other users. It's part of the Add Friend dialog. The Xfire client puts up one text box that populates the "name" attribute of this packet. The server responds with a User Search Results packet.

Packet ID 12
Attribute Key Domain String
Direction Client to Server

Attribute Map Contents:
KeyTypeDetails
name String The main search string. Matches against username, first name, last name, and/or email address.
fname String A search string which will match only on first names.
lname String A search string which will match only on last names.
email String A search string which will match only on email addresses.

Connection Keep-alive Packet

SECTION NEEDS UPDATES

This message is sent periodically by the client to notify the server it is still alive. It is not known how long a client can wait before sending a keepalive message, however the OpenFire library sends one every 60 seconds if there is no other outgoing connection activity.

Packet ID 13
Attribute Key Domain string
Direction Client to Server
Attribute Name Type Details
value 32-bit integer An integer of unknown purpose. In all analysed data to date this has had the value "0".
stats 32-bit integer list An integer list of unknown purpose. In all analysed data to date this has been an empty list.

Change Nickname Packet

The client sends this to the Xfire server to change their nickname.

Packet ID 14
Attribute Key Domain String
Direction Client to Server

Attribute Map Contents:
KeyTypeDetails
nick String The new nickname.

Client Information Packet

The client sends this packet to the Xfire server as soon as it has successfully logged in (received a Login Success packet). It indicates the language in use by the client as well as the skin and associated theme.

Packet ID 16
Attribute Key Domain String
Direction Client to Server

Attribute Map Contents:
KeyTypeDetails
lang String A language or locale string for the client's configuration. Not all exact values and their associated meanings are known, but "us" appears to mean United States English.
skin String The skin currently being used by the user's client. The default skin in new Xfire installations (as of this writing) was "Shadow".
theme String The currently selected theme (associated with the skin) in the user's client. The default theme in new Xfire installations (as of this writing) was "default".
partner String A string of unknown purpose. In all observed data, this has been an empty string.

Client Network Information Packet

The client sends this packet to indicate its view of the network configuration. It is sent shortly after a succeful log in (see Login Success packet).

Packet ID 17
Attribute Key Domain String
Direction Client to Server

Attribute Map Contents:
KeyTypeDetails
conn Integer An integer of unknown purpose, possibly indicating the type of connection. In all observed data this has had the value 2.
nat Integer This appears to be a boolean value indicating whether the client is behind a NAT device.
sec Integer An integer of unknown purpose. In all analyzed data this has had the value 5.
clientip Integer This appears to be the client's local IP address in non-network byte order (that is, little endian. This is the direct IP address of the client's machine.
naterr Integer This appears to be a boolean value indicating whether NAT override errors were detected. The official Xfire client supports UPnP and thus can create openings in certain NAT devices to allow peer to peer communication.
upnpinfo String A string indicating the UPnP configuration string the client managed to successfully use. This may be an empty string.

Client Skin Packet (Deprecated)

This packet was once used to communicate client skin and theme information to the Xfire server. It appears to have been abandoned in favor of the Client Information packet.

Packet ID 18
Attribute Key Domain String
Direction Client to Server

Unknown Packet 24

This appears to be related to using a download channel. When climsg = 17700, it apears to be a request for update (new file?) information for a channel.

Packet ID 24
Attribute Key Domain String
Direction Client to Server

Attribute Map Contents:
KeyTypeDetails
climsg Integer This appears to be a command, similar to chat message packets.
msg Attribute Map (Integer Key) This appears to have different content depending upon the climsg attribute value.

The content of the msg attribute depends upon the climsg attribute.